<template>
  <a-modal
    :visible="visible"
    title="预答辩审核"
    :width="1200"
    :bodyStyle="{
      'max-height': '76vh',
      overflow: 'auto'
    }"
    style="top: 20px;"
    :okText="isCheck ? '提交审核' : '导出预答辩' "
    @cancel="() => { $emit('cancel') }"
    @ok="confirm"
  >
    <detail-list :col="4">
      <detail-list-item term="学号">{{ defendedInfo.xh }}</detail-list-item>
      <detail-list-item term="姓名">{{ defendedInfo.xm }}</detail-list-item>
      <detail-list-item term="院系">{{ defendedInfo.dwmc }}</detail-list-item>
      <detail-list-item term="专业">{{ defendedInfo.zymc }}</detail-list-item>
      <detail-list-item term="研究方向">{{ defendedInfo.yjfxmc }}</detail-list-item>
      <detail-list-item term="学生类别">{{ defendedInfo.xslbmc }}</detail-list-item>
      <detail-list-item term="入学年月">{{ defendedInfo.rxny && defendedInfo.rxny.format('YYYY-MM-DD') }}</detail-list-item>
      <detail-list-item term="导师姓名">{{ defendedInfo.dsxm }}</detail-list-item>
      <detail-list-item term="课程学习情况">已修{{ defendedInfo.yxxf }}学分</detail-list-item>
      <detail-list-item term="有无重修课程">{{ defendedInfo.ywcxkc }}</detail-list-item>
      <detail-list-item term="论文题目">{{ defendedInfo.lwtm }}</detail-list-item>
      <detail-list-item term="题目来源">{{ defendedInfo.tmlymc || defendedInfo.tmly }}</detail-list-item>
      <detail-list-item term="是否不宜公开">{{ defendedInfo.sfbygkmc }}</detail-list-item>
    </detail-list>
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">一、预期目标实现情况</div>
    {{ defendedInfo.yqmbsxqk }}
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">二、论文的创新点</div>
    {{ defendedInfo.lwcxd }}
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">三、与国内（外）最新研究成果的比较</div>
    {{ defendedInfo.zxcgbj }}
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">四、有何待解决的问题和更深一步研究的意义</div>
    {{ defendedInfo.wtyyy }}
    <a-form v-if="isCheck" :form="form">
      <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">五、评审专家</div>
      <a-table
        rowKey="index"
        :columns="zjcolumns"
        :dataSource="tableData"
        :pagination="false"
      >
        <template v-for="col in ['xm', 'zc','dw']" :slot="col" slot-scope="text, record">
          <a-input v-if="record.editable" :key="col" v-model="record[col]"/>
          <div v-else :key="col">{{ record[col] }}</div>
        </template>
        <template slot="action" slot-scope="text,record,index">
          <a v-if="record.editable" @click="completeAdd(record)">确定</a>
          <a v-else @click="remove(index)">删除</a>
        </template>
      </a-table>
      <a-button style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed" icon="plus" @click="newRow">新增行</a-button>
      <div style="margin: 10px 0;font-weight: bold;">预答辩专家对论文的基本评价</div>
      <a-row :gutter="16">
        <a-col :md="8" :sm="12">
          <a-form-item label="论文格式规范与否" >
            <a-select v-decorator="['zjzpjLwgsgfyf',
              {
                rules: [{ required: true, message: '请选择论文格式规范与否!' }],
              }]">
              <a-select-option v-for="i in TYPE0139" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item label="文字和图表质量如何" >
            <a-select v-decorator="['zjzpjWzhtbzlrh',
              {
                rules: [{ required: true, message: '请选择文字和图表质量如何!' }],
              }]">
              <a-select-option v-for="i in TYPE0140" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item label="是否需要修改" >
            <a-select v-decorator="['zjzpjSfxyxg',
              {
                rules: [{ required: true, message: '请选择是否需要修改!' }],
              }]">
              <a-select-option v-for="i in TYPE0141" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item label="是否延期申请学位" >
            <a-select v-decorator="['zjzpjSfyqsqxw',
              {
                rules: [{ required: true, message: '请选择是否延期申请学位!' }],
              }]">
              <a-select-option v-for="i in TYPE0142" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item label="论文研究水平达到" >
            <a-select v-decorator="['lwyjspdj',
              {
                rules: [{ required: true, message: '请选择论文研究水平' }],
              }]">
              <a-select-option v-for="i in TYPE0143" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-form-item label="专家组综合评价">
        <a-textarea v-decorator="['zjzzhpj',
          {
            rules: [{ required: true, message: '请输入专家组综合评价!' }],
          }]" />
      </a-form-item>

      <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">导师审核结果</div>
      <div style="margin: 10px 0;">审核结果：{{defendedInfo.ydbxxztmc}}</div>
      <div style="margin: 10px 0;">导师对预答辩的评议：{{defendedInfo.dspjyj}}</div>
      <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">院系审核结果</div>
      <a-form-item label="审核结果" style="width:30%">
        <a-select v-decorator="['yxshzt',
          {
            rules: [{ required: true, message: '请选择院系审核结果!' }],
          }]" >
          <a-select-option value="07">通过</a-select-option>
          <a-select-option value="78">建议修改或补充</a-select-option>
          <a-select-option value="08">不通过</a-select-option>
          <!-- <a-select-option v-for="i in TYPE0136" :key="i.id" :value="i.code">{{ i.name }}</a-select-option> -->
        </a-select>
      </a-form-item>

    </a-form>
  </a-modal>

</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import DetailList from '~/tool/DetailList'
const DetailListItem = DetailList.Item

export default {
  props: ['visible', 'isCheck'],
  components: {DetailList, DetailListItem, STable},
  data () {
    return {
      form: this.$form.createForm(this),
      defendedInfo: {
      },
      tableData: [],
      completeData: [],
      zjcolumns: [
        {
          title: '姓名',
          scopedSlots: { customRender: 'xm' }
        },
        {
          title: '职称',
          scopedSlots: { customRender: 'zc' }
        },
        {
          title: '所在单位、现从事专业',
          scopedSlots: { customRender: 'dw' }
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.form.resetFields()
        this.tableData = []
      }
    }
  },
  computed: {
    ...mapState({
      // TYPE0136: state => state.app['TYPE0136'],
      TYPE0139: state => state.app['TYPE0139'],
      TYPE0140: state => state.app['TYPE0140'],
      TYPE0141: state => state.app['TYPE0141'],
      TYPE0142: state => state.app['TYPE0142'],
      TYPE0143: state => state.app['TYPE0143']
    })
  },
  created () {
    // this.$store.dispatch('app/setDictionary', 'TYPE0136')
    this.$store.dispatch('app/setDictionary', 'TYPE0139')
    this.$store.dispatch('app/setDictionary', 'TYPE0140')
    this.$store.dispatch('app/setDictionary', 'TYPE0141')
    this.$store.dispatch('app/setDictionary', 'TYPE0142')
    this.$store.dispatch('app/setDictionary', 'TYPE0143')
  },
  methods: {
    newRow () {
      let hasEdit = this.tableData.find(d => {
        return d.editable
      })
      if (hasEdit) {
        return this.$message.warning('请先完成前面的添加')
      }
      this.tableData.push({
        xm: '',
        zc: '',
        dw: '',
        action: '',
        editable: true
      })
    },
    remove (index) {
      this.tableData.splice(index, 1)
    },
    completeAdd (data) {
      if (data.xm && data.zc && data.dw) {
        this.completeData.push(data)
        return this.$set(data, 'editable', false)
      }
      this.$message.error('请输入完整的评审专家信息')
    },
    confirm () {
      if (this.isCheck) {
        this.form.validateFields((err, values) => {
          if (err) {
            return
          }
          if (!this.completeData.length) {
            return this.$message.error('评审专家不能为空')
          }
          let params = Object.assign({}, values, {
            ydbxxId: this.defendedInfo.id,
            pszhjson: JSON.stringify(this.completeData)
          })
          this.$api.cultivate.defendedCheck(params).then(res => {
            this.$message.success(res.msg)
            this.$emit('cancel')
            this.$emit('refresh')
          })
        })
      } else {
        this.$export(`/foster/ydbxx/ydbExp`, {id: this.defendedInfo.id})
      }
    }
  }
}
</script>

<style lang='less' scoped>
.pre-red::before{
    display: inline-block;
    margin-right: 4px;
    content: "*";
    font-family: SimSun;
    line-height: 1;
    font-size: 14px;
    color: #f5222d;
}
</style>
